﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NapCardOnline.Models
{
    public partial class Service
    {
        /// <summary>
        /// Gets all service.
        /// </summary>
        /// <returns>The list of service</returns>
        public static List<Service> GetAllService()
        {
            using (var db = new NapCardOnlineEntities())
            {
                return db.Services.ToList();
            }
        }

        /// <summary>                
        /// Gets the service by parent service id.
        /// </summary>
        /// <param name="parentId">The parent id.</param>
        /// <returns></returns>
        public static List<Service> GetServiceByParentServiceId(int parentId)
        {
            using (var db = new NapCardOnlineEntities())
            {
                return db.Services.Where(s => s.ParentServiceID == parentId).ToList();
            }
        }

        /// <summary>
        /// Gets the service by service no.
        /// </summary>
        /// <param name="serviceNo">The service no.</param>
        /// <returns>The service object</returns>
        public static Service GetServiceByServiceNo(string serviceNo)
        {
            using (var db = new NapCardOnlineEntities())
            {
                return db.Services.FirstOrDefault(s => s.ServiceNo == serviceNo);
            }
        }

        /// <summary>
        /// Gets the service id by service no.
        /// </summary>
        /// <param name="serviceNo">The service no.</param>
        /// <returns>The service Id</returns>
        public static int GetServiceIdByServiceNo(string serviceNo)
        {
            var objService = GetServiceByServiceNo(serviceNo);
            return objService.ServiceID;
        }

        public static Service GetServiceByServiceId(int serviceId)
        {
            using (var db = new NapCardOnlineEntities())
            {
                return db.Services.FirstOrDefault(s => s.ServiceID == serviceId);
            }
        }

        public static int GetServiceIdByServiceCostId(int serviceCostId)
        {
            using (var db = new NapCardOnlineEntities())
            {
                var objServiceCost = db.ServiceCosts.FirstOrDefault(s => s.ServiceCostID == serviceCostId);
                if (objServiceCost != null)
                {
                    return objServiceCost.FK_ServiceID;
                }
                return 0;
            }
        }

        public static string GetServiceNumberHeadeByServiceId(int serviceId)
        {
            var objService = GetServiceByServiceId(serviceId);
            return objService.ServiceNumberHead;
        }

    }
}